



function optEvent() {
    return '<button type="button"  class="layui-btn layui-btn-info layui-btn-mini display">详情</button>'
}

window.optEvents = {
    "click .display":function (e,value,row) {
        var drugNum = row.drugNum;//药品编号
        location.href=ctx+"/stock/display?drugNum="+drugNum;
    }
}
//条件查询
function searchByWhere() {
    var param = {};
    param.drugName=$("#DrugstockForm [name=drugName]").val();//药瓶品名称
    param.stoLotnum=$("#DrugstockForm [name=stoLotnum]").val();//批号
    $("#drugstockTable").bootstrapTable("refresh",{query:param})
}
//详情操作
function optEvent2() {
    return '<button type="button"  class="layui-btn layui-btn-info layui-btn-mini edit">编辑</button>'
}
window.optEvents2= {
    "click .edit":function (e,value,row) {
        $("#edit").dialog("open");
        $("#editForm [name=drugName]").val(row.druginfo.drugName)
        $("#editForm").setForm(row);
    }
}
function initEdit() {
    $("#edit").dialog({
        title:"修改库存信息",
        btnValue:"修改",
        addBind:function () {
            $("#editForm input").change(function () {
                $(this).parent().siblings("span").html("")
            })
            var stoLotnum = $("#editForm [name=stoLotnum]").val();
            var stoPutindate=$("#editForm [name=stoPutindate]").val();//入库日期
            var stoMfg=$("#editForm [name=stoMfg]").val();//生产日期
            var stoValiddate = $("#editForm [name=stoValiddate]").val();//有效日期
            var stoPcs = $("#editForm [name=stoPcs]").val();//数量
            var stoPrimecost = $("#editForm [name=stoPrimecost]").val();//进价
            var stoPresell = $("#editForm [name=stoPresell]").val();//预售价
            if(stoLotnum==null || stoLotnum==''){
                $("#editForm [name=stoLotnum]").parent().siblings("span").html("批号不能为空!");
                return;
            }
            if(stoPutindate==null || stoPutindate==''){
                $("#editForm [name=stoPutindate]").parent().siblings("span").html("日期不能为空!");
                return;
            }else if(stoMfg==null || stoMfg==''){
                $("#editForm [name=stoMfg]").parent().siblings("span").html("日期不能为空!");
                return;
            }else if(stoValiddate==null || stoValiddate==''){
                $("#editForm [name=stoValiddate]").parent().siblings("span").html("日期不能为空!");
                return;
            }else if(stoPcs==null || stoPcs==''){
                $("#editForm [name=stoPcs]").parent().siblings("span").html("数量不能为空!");
                return;
            }else if(stoPcs<0){
                $("#editForm [name=stoPcs]").parent().siblings("span").html("数量不正确!");
                return;
            }else if(stoPrimecost==null || stoPrimecost==''){
                $("#editForm [name=stoPrimecost]").parent().siblings("span").html("价格不正确!");
                return;
            }else if(stoPresell==null || stoPresell==''){
                $("#editForm [name=stoPresell]").parent().siblings("span").html("价格不正确!");
                return;
            }
           var param = $("#edit").find("form").serialize();
            $.post(ctx+"/stock/update",param,function (msg) {
                $("#edit").dialog("close");
                toastr.warning(msg);
                searchBudrugNum();
            })
        }
    })
}
$(function () {
    initEdit();
});
//第一个详细信息查询
function searchBudrugNum() {
    var param={};
    param.stoLotnum=$("#detailForm [name=stoLotnum]").val();
    param.guoQi=$("#detailForm [name=guoQi]").val();
    param.stoPutindateStart=$("#detailForm [name=stoPutindateStart]").val();
    param.stoPutindateEnd=$("#detailForm [name=stoPutindateEnd]").val();
    param.stoMfgStart=$("#detailForm [name=stoMfgStart]").val();
    param.stoMfgEnd=$("#detailForm [name=stoMfgEnd]").val();
    var countStart=$("#detailForm [name=countStart]").val();

    if(countStart==''){
        param.countStart=-1;
    }else{
        param.countStart=$("#detailForm [name=countStart]").val();
    }
    var countEnd=$("#detailForm [name=countEnd]").val();
    if(countEnd==''){
        param.countEnd=-1;
    }else{
        param.countEnd=$("#detailForm [name=countEnd]").val();
    }
    $("#drugstockTable").bootstrapTable("refresh",{query:param})
}

$(function () {
    laydate.render({
        elem:'[name=stoPutindateStart]'
    })
    laydate.render({
        elem:'[name=stoPutindateEnd]'
    })
    laydate.render({
        elem:'[name=stoPutindateStart]'
    })
    laydate.render({
        elem:'[name=stoPutindateEnd]'
    })
    laydate.render({
        elem:'[name=stoMfgStart]'
    })
    laydate.render({
        elem:'[name=stoMfgEnd]'
    })
});
